package com.zscat.mallplus.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zscat.mallplus.annotation.IgnoreAuth;
import com.zscat.mallplus.annotation.SysLog;
import com.zscat.mallplus.cms.entity.*;
import com.zscat.mallplus.cms.mapper.CmsSubjectMapper;
import com.zscat.mallplus.cms.service.*;
import com.zscat.mallplus.enums.ConstansValue;
import com.zscat.mallplus.pay.utils.StringUtils;
import com.zscat.mallplus.pms.entity.CmsSubjectProductRelation;
import com.zscat.mallplus.pms.entity.PmsComment;
import com.zscat.mallplus.pms.entity.PmsProduct;
import com.zscat.mallplus.pms.mapper.CmsSubjectProductRelationMapper;
import com.zscat.mallplus.pms.service.IPmsProductAttributeCategoryService;
import com.zscat.mallplus.pms.service.IPmsProductCategoryService;
import com.zscat.mallplus.pms.service.IPmsProductService;
import com.zscat.mallplus.sms.service.ISmsGroupService;
import com.zscat.mallplus.sys.entity.MallplusKeyword;
import com.zscat.mallplus.sys.entity.MallplusSearchHistory;
import com.zscat.mallplus.sys.mapper.MallplusKeywordMapper;
import com.zscat.mallplus.sys.mapper.MallplusSearchHistoryMapper;
import com.zscat.mallplus.ums.entity.UmsMember;
import com.zscat.mallplus.ums.entity.UmsMemberLevel;
import com.zscat.mallplus.ums.entity.UmsRewardLog;
import com.zscat.mallplus.ums.mapper.UmsMemberMapper;
import com.zscat.mallplus.ums.mapper.UmsRewardLogMapper;
import com.zscat.mallplus.ums.service.IUmsMemberLevelService;
import com.zscat.mallplus.ums.service.IUmsMemberService;
import com.zscat.mallplus.ums.service.IUmsRewardLogService;
import com.zscat.mallplus.ums.service.impl.RedisUtil;
import com.zscat.mallplus.utils.BaseEntity;
import com.zscat.mallplus.utils.CommonResult;
import com.zscat.mallplus.utils.ValidatorUtils;
import com.zscat.mallplus.vo.Rediskey;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author king
 * @Date: 2019/4/2 15:02
 */
@RestController
@Api(tags = "CmsController", description = "内容关系管理")
@RequestMapping("/api/single/cms")
public class CmsController extends ApiBaseAction {
    @Resource
    private CmsSubjectMapper subjectMapper;
    @Resource
    private ISmsGroupService groupService;
    @Resource
    private IUmsMemberLevelService memberLevelService;
    @Resource
    private IPmsProductService pmsProductService;
    @Resource
    private IPmsProductAttributeCategoryService productAttributeCategoryService;
    @Resource
    private IPmsProductCategoryService productCategoryService;
    @Resource
    private ICmsTopicService topicService;
    @Resource
    private ICmsSubjectCategoryService subjectCategoryService;
    @Resource
    private ICmsSubjectService subjectService;
    @Resource
    private ICmsSubjectCommentService subjectCommentService;
    @Resource
    private ICmsTopicCommentService topicCommentService;
    @Resource
    private UmsMemberMapper memberMapper;
    @Resource
    private UmsRewardLogMapper rewardLogMapper;
    @Resource
    private IUmsRewardLogService rewardLogService;
    @Resource
    private RedisUtil redisUtil;
    @Resource
    private IUmsMemberService memberService;
    @Resource
    private CmsSubjectProductRelationMapper subjectProductRelationMapper;
    @Resource
    private ICmsZhaoPinService ICmsZhaoPinService;
    @Resource
    private ICmsHelpService helpService;
    @Resource
    private ICmsHelpCategoryService helpCategoryService;

    @IgnoreAuth
    @SysLog(MODULE = "cms", REMARK = "查询文章列表")
    @ApiOperation(value = "查询文章列表")
    @GetMapping(value = "/subject/list")
    public Object subjectList(String keyword,
    						  @RequestParam(value = "categoryId", required = false) Long categoryId,
    						  @RequestParam(value = "storeId", required = false) Integer storeId,
                              @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                              @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum) {
        CmsSubject subject = new CmsSubject();
        if (ValidatorUtils.notEmpty(categoryId)) {
            subject.setCategoryId(categoryId);
        }
        if (ValidatorUtils.notEmpty(storeId)) {
            subject.setStoreId(storeId);
        }
        //设置显示状态
        subject.setShowStatus(1);
        QueryWrapper<CmsSubject> queryWrapper = new QueryWrapper<>(subject);
        if (Objects.nonNull(keyword) && StringUtils.isNotBlank(keyword)) {
        	keyword = "%" + keyword.replace(" ", "") + "%";
            queryWrapper.like("title", keyword);
        }
        
        return new CommonResult().success(subjectService.page(new Page<CmsSubject>(pageNum, pageSize), queryWrapper.select(ConstansValue.sampleSubjectList).orderByDesc("is_top").orderByDesc("create_time")));
//        }
//        if (subject.getType() == 1) {
//            return new CommonResult().success(subjectService.page(new Page<CmsSubject>(pageNum, pageSize), new QueryWrapper<>(subject).select(ConstansValue.sampleSubjectList).orderByDesc("read_count")));
//        } else if (subject.getType() == 2) {
//            return new CommonResult().success(subjectService.page(new Page<CmsSubject>(pageNum, pageSize), new QueryWrapper<>(subject).select(ConstansValue.sampleSubjectList).orderByDesc("collect_count")));
//        } else if (subject.getType() == 3) {
//            return new CommonResult().success(subjectService.page(new Page<CmsSubject>(pageNum, pageSize), new QueryWrapper<>(subject).select(ConstansValue.sampleSubjectList).orderByDesc("comment_count")));
//        }
//        return new CommonResult().success(subjectService.page(new Page<CmsSubject>(pageNum, pageSize), new QueryWrapper<>(subject).select(ConstansValue.sampleSubjectList).orderByDesc("create_time")));
    }


    @SysLog(MODULE = "cms", REMARK = "查询文章分类列表")
    @IgnoreAuth
    @ApiOperation(value = "查询文章分类列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "storeId", value = "店铺编号", required = false, dataType = "Long", paramType = "query"),
            @ApiImplicitParam(name = "id", value = "文章分类编号", required = false, dataType = "Long", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "文章分类名称", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "icon", value = "文章分类图标", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "subjectCount", value = "专题数量", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "showStatus", value = "是否显示：0->不显示；1->显示", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "sort", value = "排序", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageNum", value = "当前页", required = false, dataType = "int", paramType = "query", defaultValue = "1"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数", required = false, dataType = "int", paramType = "query", defaultValue = "10")
    })
    @GetMapping(value = "/subjectCategory/list")
    public Object cateList(CmsSubjectCategory subjectCategory,
                           @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                           @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum) {
        subjectCategory.setStoreId(1);
        return new CommonResult().success(subjectCategoryService.page(new Page<CmsSubjectCategory>(pageNum, pageSize), new QueryWrapper<>(subjectCategory)));
    }

    @SysLog(MODULE = "cms", REMARK = "查询文章评论列表")
    @IgnoreAuth
    @ApiOperation(value = "查询文章评论列表")
    @GetMapping(value = "/subjectComment/list")
    public Object subjectList(CmsSubjectComment subjectComment,
                              @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                              @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum) {
        return new CommonResult().success(subjectCommentService.page(new Page<CmsSubjectComment>(pageNum, pageSize), new QueryWrapper<>(subjectComment).orderByDesc("create_time")));
    }

    /**
     * 发现推荐
     *
     * @param pageSize
     * @param pageNum
     * @return
     */
    @IgnoreAuth
    @GetMapping(value = "/recommendSubjectList/list")
    public Object getRecommendSubjectList(
    		@RequestParam(value = "storeId", required = false) Integer storeId,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
            @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum, String title) {

        IPage<CmsSubject> cmsSubjectIPage = subjectService.page(
                new Page<CmsSubject>(pageNum, pageSize),
                new QueryWrapper<CmsSubject>()
                        .lambda()
                        .eq(BaseEntity::getStoreId, storeId)
                        .eq(CmsSubject::getRecommendStatus, 1)
                        .eq(CmsSubject::getShowStatus, 1)
                        .like(StringUtils.isNoneEmpty(title), CmsSubject::getTitle, title)
                        .orderByDesc(CmsSubject::getCreateTime)
        );
        return new CommonResult().success(cmsSubjectIPage);
    }

    @IgnoreAuth
    @SysLog(MODULE = "pms", REMARK = "查询文章详情信息")
    @ApiOperation(value = "查询文章详情")
    @ApiImplicitParam(name = "id", value = "文章编号", required = true, dataType = "Long", paramType = "query")
    @GetMapping(value = "/subject/detail")
    public Object subjectDetail(@RequestParam(value = "id", required = true, defaultValue = "0") Long id) {
        CmsSubject productResult = subjectService.getById(id);
        List<CmsSubjectProductRelation> list = subjectProductRelationMapper.selectList(new QueryWrapper<CmsSubjectProductRelation>().eq("subject_id", id));

        if (list != null && list.size() > 0) {
            List<Long> ids = list.stream()
                    .map(CmsSubjectProductRelation::getProductId)
                    .collect(Collectors.toList());
            List<PmsProduct> products = (List<PmsProduct>) pmsProductService.list(new QueryWrapper<PmsProduct>().in("id", ids).select(ConstansValue.sampleGoodsList));
            productResult.setProducts(products);
        }

        //记录浏览量到redis,然后定时更新到数据库
        String key = Rediskey.ARTICLE_VIEWCOUNT_CODE + id;
        //找到redis中该篇文章的点赞数，如果不存在则向redis中添加一条
        Map<Object, Object> viewCountItem = redisUtil.hGetAll(Rediskey.ARTICLE_VIEWCOUNT_KEY);
        Integer viewCount = 0;
        if (!viewCountItem.isEmpty()) {
            if (viewCountItem.containsKey(key)) {
                viewCount = Integer.parseInt(viewCountItem.get(key).toString()) + 1;
                redisUtil.hPut(Rediskey.ARTICLE_VIEWCOUNT_KEY, key, viewCount + "");
            } else {
                viewCount = 1;
                redisUtil.hPut(Rediskey.ARTICLE_VIEWCOUNT_KEY, key, 1 + "");
            }
        } else {
            viewCount = 1;
            redisUtil.hPut(Rediskey.ARTICLE_VIEWCOUNT_KEY, key, 1 + "");
        }
        productResult.setReadCount(viewCount);
        return new CommonResult().success(productResult);
    }

//    @SysLog(MODULE = "cms", REMARK = "查询帮助文档列表")
//    @ApiOperation(value = "查询帮助文档列表")
//    @GetMapping(value = "/help/list")
//    public Object help(CmsHelp subject,
//                             @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
//                             @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum) {
//        return new CommonResult().success(helpService.page(new Page<CmsHelp>(pageNum, pageSize), new QueryWrapper<>(subject).orderByDesc("create_time")));
//    }
//    @SysLog(MODULE = "cms", REMARK = "查询帮助文档分类列表")
//    @ApiOperation(value = "查询帮助文档分类列表")
//    @GetMapping(value = "/helpCategory/list")
//    public Object helpCategory(CmsHelpCategory subject,
//                             @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
//                             @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum) {
//        return new CommonResult().success(helpCategoryService.page(new Page<CmsHelpCategory>(pageNum, pageSize), new QueryWrapper<>(subject).orderByDesc("sort")));
//    }
//    @SysLog(MODULE = "cms", REMARK = "查询专题详情信息")
//    @IgnoreAuth
//    @GetMapping(value = "/help/detail")
//    @ApiOperation(value = "查询公益详情信息")
//    public Object helpDetail(@RequestParam(value = "id", required = false, defaultValue = "0") Long id) {
//        return new CommonResult().success(helpService.getById(id));
//    }
//    @SysLog(MODULE = "cms", REMARK = "查询专题详情信息")
//    @IgnoreAuth
//    @GetMapping(value = "/helpCategory/detail")
//    @ApiOperation(value = "查询公益详情信息")
//    public Object helpCategoryDetail(@RequestParam(value = "id", required = false, defaultValue = "0") Long id) {
//        return new CommonResult().success(helpCategoryService.getById(id));
//    }
//    @IgnoreAuth
//    @SysLog(MODULE = "cms", REMARK = "查询招聘列表")
//    @ApiOperation(value = "查询招聘列表")
//    @GetMapping(value = "/zhaopin/list")
//    public Object rewardList(CmsZhaoPin subject,
//                             @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
//                             @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum) {
//        return new CommonResult().success(ICmsZhaoPinService.page(new Page<CmsZhaoPin>(pageNum, pageSize), new QueryWrapper<>(subject).orderByDesc("create_time")));
//    }
//
//    @IgnoreAuth
//    @SysLog(MODULE = "cms", REMARK = "查询打赏列表")
//    @ApiOperation(value = "查询打赏列表")
//    @GetMapping(value = "/reward/list")
//    public Object rewardList(UmsRewardLog subject,
//                             @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
//                             @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum) {
//        return new CommonResult().success(rewardLogService.page(new Page<UmsRewardLog>(pageNum, pageSize), new QueryWrapper<>(subject).orderByDesc("create_time")));
//    }


    //    @IgnoreAuth
//    @SysLog(MODULE = "cms", REMARK = "查询文章列表")
//    @ApiOperation(value = "查询文章列表")
//    @GetMapping(value = "/subjectDetail/list")
//    public Object subjectDetailList(CmsSubject subject,
//                              @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
//                              @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum) {
//
//        IPage<CmsSubject> page = null;
//        if (ValidatorUtils.empty(subject.getType())) {
//            page = subjectService.page(new Page<CmsSubject>(pageNum, pageSize), new QueryWrapper<>(subject).select(ConstansValue.sampleSubjectList).orderByDesc("create_time"));
//        }
//        if (subject.getType() == 1) {
//            page =subjectService.page(new Page<CmsSubject>(pageNum, pageSize), new QueryWrapper<>(subject).select(ConstansValue.sampleSubjectList).orderByDesc("read_count"));
//        } else if (subject.getType() == 2) {
//            page =subjectService.page(new Page<CmsSubject>(pageNum, pageSize), new QueryWrapper<>(subject).select(ConstansValue.sampleSubjectList).orderByDesc("collect_count"));
//        } else if (subject.getType() == 3) {
//            page = subjectService.page(new Page<CmsSubject>(pageNum, pageSize), new QueryWrapper<>(subject).select(ConstansValue.sampleSubjectList).orderByDesc("comment_count"));
//        }
//        for (CmsSubject omsOrder : page.getRecords()) {
//            List<CmsSubjectComment> subjectCommentList = commentService.list(new QueryWrapper<CmsSubjectComment>().eq("subject_id", omsOrder.getId()));
//            omsOrder.setSubjectCommentList(subjectCommentList);
//        }
//        return new CommonResult().success(page);
//    }


//    @SysLog(MODULE = "pms", REMARK = "查询首页推荐文章")
//    @IgnoreAuth
//    @ApiOperation(value = "查询首页推荐文章")
//    @GetMapping(value = "/recommendSubjectList/list")
//    public Object getRecommendSubjectList(
//            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
//            @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum) {
//
//        return new CommonResult().success(subjectService.getRecommendSubjectList(1, 1));
//    }


//    @SysLog(MODULE = "cms", REMARK = "查询专题列表")
//    @IgnoreAuth
//    @ApiOperation(value = "查询公益列表")
//    @GetMapping(value = "/topic/list")
//    public Object subjectList(CmsTopic topic,
//                              @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
//                              @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum) {
//        return new CommonResult().success(topicService.page(new Page<CmsTopic>(pageNum, pageSize), new QueryWrapper<>(topic).orderByDesc("create_time")));
//    }
//
//    @SysLog(MODULE = "cms", REMARK = "查询专题列表")
//    @IgnoreAuth
//    @ApiOperation(value = "查询公益评论列表")
//    @GetMapping(value = "/topicComment/list")
//    public Object subjectList(CmsTopicComment topic,
//                              @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
//                              @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum) {
//        return new CommonResult().success(topicCommentService.page(new Page<CmsTopicComment>(pageNum, pageSize), new QueryWrapper<>(topic).orderByDesc("create_time")));
//    }
//
//    @SysLog(MODULE = "pms", REMARK = "查询专题详情信息")
//    @IgnoreAuth
//    @GetMapping(value = "/topic/detail")
//    @ApiOperation(value = "查询公益详情信息")
//    public Object topicDetail(@RequestParam(value = "id", required = false, defaultValue = "0") Long id) {
//        CmsTopic productResult = topicService.getById(id);
//        productResult.setReadCount(productResult.getReadCount() + 1);
//        topicService.updateById(productResult);
//        return new CommonResult().success(productResult);
//    }

    @SysLog(MODULE = "cms", REMARK = "文章评论")
    @ApiOperation(value = "文章评论")
    @PostMapping(value = "addSubjectComment")
    public Object addSubjectComment(CmsSubjectComment subjectComment) {
        return subjectCommentService.saveSubjectComment(subjectComment);
    }

    @ApiOperation(value = "查询文章评论列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "subjectId", value = "商品编号", required = true, dataType = "long", paramType = "query"),
            @ApiImplicitParam(name = "pageNum", value = "当前页", required = false, dataType = "int", paramType = "query", defaultValue = "1"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数", required = false, dataType = "int", paramType = "query", defaultValue = "10")
    })
    @SysLog(MODULE = "cms", REMARK = "查询文章评论列表")
    @GetMapping(value = "commentList")
    public Object commentList(@RequestParam(value = "subjectId", required = true) Long subjectId,
                              @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                              @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        if (ValidatorUtils.empty(subjectId)) {
            return new CommonResult().failed("文章ID不能为空");
        }

        return new CommonResult().success(subjectCommentService.page(new Page<CmsSubjectComment>(pageNum, pageSize), new QueryWrapper<CmsSubjectComment>().eq("subject_id", subjectId).eq("show_status", 0).orderByDesc("create_time")));
    }

//    @SysLog(MODULE = "cms", REMARK = "创建公益")
//    @ApiOperation(value = "发布公益")
//    @PostMapping(value = "/createTopic")
//    public Object createTopic(CmsTopic subject, BindingResult result) {
//        CommonResult commonResult;
//        UmsMember member = memberService.getNewCurrentMember();
//        if (member != null) {
//            subject.setMemberId(member.getId());
//            subject.setMemberName(member.getNickname());
//        } else {
//            return new CommonResult().failed("请先登录");
//        }
//
//        if (subject.getQsType() == 1) {
//            subject.setSchoolName(member.getSchoolName());
//            subject.setSchoolId(member.getSchoolId());
//        } else {
//            subject.setAreaName(member.getAreaName());
//            subject.setAreaId(member.getAreaId());
//        }
//
//        subject.setReadCount(0);
//        subject.setAttendCount(0);
//        subject.setAttentionCount(0);
//        subject.setCreateTime(new Date());
//        boolean count = topicService.save(subject);
//        if (count) {
//            commonResult = new CommonResult().success(count);
//        } else {
//            commonResult = new CommonResult().failed();
//        }
//        return commonResult;
//    }

//    @SysLog(MODULE = "cms", REMARK = "参加公益")
//    @ApiOperation(value = "参加公益 公益id")
//    @PostMapping(value = "/attendTopic")
//    public Object attendTopic(@RequestParam(value = "id", required = false, defaultValue = "0") Long id) {
//        CommonResult commonResult;
//        UmsMember member = memberService.getNewCurrentMember();
//
//        CmsTopic subject = topicService.getById(id);
//        Date now = new Date();
//        if (now.getTime() > subject.getEndTime().getTime() || now.getTime() < subject.getStartTime().getTime()) {
//            return new CommonResult().failed("未开始或者已过期");
//        }
//        if (member != null) {
//            if (ValidatorUtils.notEmpty(subject.getAtids())) {
//                String[] values = subject.getAtids().split(",");
//                List<String> list = Arrays.asList(values);
//                if (list.contains(member.getId() + "")) {
//                    return new CommonResult().failed("你已参加该活动");
//                } else {
//                    list.add(member.getId() + "");
//                    subject.setAtids(Arrays.toString(list.toArray()));
//                }
//            }
//
//        } else {
//            return new CommonResult().failed("请先登录");
//        }
//        subject.setReadCount(subject.getReadCount() + 1);
//        subject.setAttendCount(subject.getAttendCount() + 1);
//
//        boolean count = topicService.updateById(subject);
//        if (count) {
//            commonResult = new CommonResult().success(count);
//        } else {
//            commonResult = new CommonResult().failed();
//        }
//        return commonResult;
//    }

//    @SysLog(MODULE = "cms", REMARK = "参加公益")
//    @ApiOperation(value = "取消参加公益 公益id")
//    @PostMapping(value = "/canceTopic")
//    public Object canceTopic(@RequestParam(value = "id", required = false, defaultValue = "0") Long id) {
//        CommonResult commonResult;
//        UmsMember member = memberService.getNewCurrentMember();
//        CmsTopic subject = topicService.getById(id);
//
//        if (member != null) {
//            if (ValidatorUtils.notEmpty(subject.getAtids())) {
//                String[] values = subject.getAtids().split(",");
//                List<String> list = Arrays.asList(values);
//                if (list.contains(member.getId() + "")) {
//                    list.remove(member.getId() + "");
//                    subject.setAtids(Arrays.toString(list.toArray()));
//                }
//            }
//
//        } else {
//            return new CommonResult().failed("请先登录");
//        }
//        subject.setReadCount(subject.getReadCount() - 1);
//        subject.setAttendCount(subject.getAttendCount() - 1);
//
//        boolean count = topicService.updateById(subject);
//        if (count) {
//            commonResult = new CommonResult().success(count);
//        } else {
//            commonResult = new CommonResult().failed();
//        }
//        return commonResult;
//    }

//    @SysLog(MODULE = "cms", REMARK = "参加公益")
//    @ApiOperation(value = "关注公益 公益id，点一次关注按钮，记录一下关注数量，不去重 不需要登录")
//    @PostMapping(value = "/favoriteTopic")
//    public Object favoriteTopic(@RequestParam(value = "id", required = false, defaultValue = "0") Long id) {
//        CommonResult commonResult;
//        CmsTopic subject = topicService.getById(id);
//        subject.setAttentionCount(subject.getAttentionCount() + 1);
//        boolean count = topicService.updateById(subject);
//        if (count) {
//            commonResult = new CommonResult().success(count);
//        } else {
//            commonResult = new CommonResult().failed();
//        }
//        return commonResult;
//    }

//    @SysLog(MODULE = "cms", REMARK = "创建文章")
//    @ApiOperation(value = "添加文章评论")
//    @PostMapping(value = "/addSubjectCom")
//    public Object addSubjectCom(CmsSubjectComment subject, BindingResult result) {
//        CommonResult commonResult;
//        UmsMember member = memberService.getNewCurrentMember();
//        if (member != null) {
//            subject.setMemberIcon(member.getIcon());
//            subject.setMemberNickName(member.getNickname());
//        } else {
//            return new CommonResult().failed("请先登录");
//        }
//        subject.setCreateTime(new Date());
//
//        boolean count = commentService.save(subject);
//        if (count) {
//            commonResult = new CommonResult().success(count);
//        } else {
//            commonResult = new CommonResult().failed();
//        }
//        return commonResult;
//    }

//    @SysLog(MODULE = "cms", REMARK = "添加招聘")
//    @ApiOperation(value = "添加招聘")
//    @PostMapping(value = "/addZhaoPin")
//    public Object addSubjectCom(CmsZhaoPin subject, BindingResult result) {
//        CommonResult commonResult;
//        subject.setCreateTime(new Date());
//        boolean count = ICmsZhaoPinService.save(subject);
//        if (count) {
//            commonResult = new CommonResult().success(count);
//        } else {
//            commonResult = new CommonResult().failed();
//        }
//        return commonResult;
//    }

//    @SysLog(MODULE = "cms", REMARK = "创建文章")
//    @ApiOperation(value = "添加公益评论")
//    @PostMapping(value = "/addTopicCom")
//    public Object addTopicCom(CmsTopicComment subject, BindingResult result) {
//        CommonResult commonResult;
//        UmsMember member = memberService.getNewCurrentMember();
//        if (member != null) {
//            subject.setMemberIcon(member.getIcon());
//            subject.setMemberNickName(member.getNickname());
//        } else {
//            return new CommonResult().failed("请先登录");
//        }
//        subject.setCreateTime(new Date());
//
//        boolean count = topicCommentService.save(subject);
//        if (count) {
//            commonResult = new CommonResult().success(count);
//        } else {
//            commonResult = new CommonResult().failed();
//        }
//        return commonResult;
//    }

//    @ApiOperation(value = "打赏文章")
//    @PostMapping(value = "/reward")
//    @SysLog(MODULE = "ums", REMARK = "打赏文章")
//    public Object reward(@RequestParam(value = "articlelId", required = true) Long articlelId,
//                         @RequestParam(value = "coin", required = true) int coin) {
//        return subjectService.reward(articlelId, coin);
//    }
//
//    @GetMapping("/listTimeline")
//    public Object listTimeline() {
//        return new CommonResult().success(subjectService.listTimeLine());
//    }

//    @IgnoreAuth
//    @SysLog(MODULE = "cms", REMARK = "查询文章列表")
//    @ApiOperation(value = "查询文章列表")
//    @GetMapping(value = "/subjectListByTime/list")
//    public Object subjectListByTime(CmsSubject subject,
//                                    @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
//                                    @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum) {
//
//        return new CommonResult().success(subjectMapper.loadArticleByArchive(subject.getCreateTimeVar()));
//    }
//
//    @IgnoreAuth
//    @SysLog(MODULE = "cms", REMARK = "查询文章列表")
//    @ApiOperation(value = "查询文章列表")
//    @GetMapping(value = "/getTime/list")
//    public Object getTime(CmsSubject subject,
//                          @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
//                          @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum) {
//
//        return new CommonResult().success(subjectMapper.articleArchiveList());
//    }
}
